package com.wwwc.admin.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;

import com.wwwc.admin.web.database.*;
import com.wwwc.util.web.*;

public class adminHtmlFileToTable {
    public StringBuffer getHtmlFile (HttpServletRequest request, String mid, String get_data_call_back, String select_call_back){
	String call_path = request.getServletPath();
	StringBuffer error = null;
	StringBuffer sbf = null;
	String in = request.getParameter("html_text");
      
	if(in != null) {
	    if(in.length()==0) {
		error = new StringBuffer("Please cut and paste your html file into the text area.");
	    }
	    else {
		sbf = new StringBuffer();
		sbf.append("<h3>Please select the range of your data to save</h3>");
		sbf.append("<FORM method='post' action='"+call_path+"'>");
		sbf.append("<TABLE border='1'><TR><TD align='center'><B>From:</B></TD>");
		sbf.append("<TD><B>To:</B></TD><TD align='center'><B>Data</B></TD></TR>"); 

		in = in.replaceAll("\n","");
		in = in.replaceAll("</","\n</");
		in = in.replaceAll("<","\n<");
		in = in.replaceAll(">",">\n");

		StringTokenizer stk = new StringTokenizer(in, "\n");
		String temp = null;
		boolean found_end = false;
		boolean found_start = false;
		int m =0;
		while(stk.hasMoreTokens()) {
		    temp = stk.nextToken();
		    temp = temp.replaceAll("&nbsp;","");
		    temp = temp.replaceAll("&nbsp","");
		    temp = temp.trim();
		   
		    if(temp != null && temp.length()>0) {
			if(!temp.startsWith("<")) {
			    if(temp.indexOf("<") != -1) {
				temp = temp.replaceAll("<", "&lt;");
			    }
			    if(temp.indexOf(">") != -1) {
				temp = temp.replaceAll(">", "&gt;");
			    }
			    if(temp.indexOf("\"") != -1) {
				temp = temp.replaceAll("\"", "");
			    }
			    sbf.append("<TR><TD><input type='radio' name='start' value='"+m+"'></TD>");
			    sbf.append("<TD><input type='radio' name='end' value='"+m+"'></TD>");
			    sbf.append("<TD>");
			    sbf.append("<input type='text' name='text"+m+"' value=\""+temp+"\" size='30' style='font-size: 8pt'>");
			    sbf.append("</TD></TR>");
			    m++;
			}
		    }
		}

		sbf.append("<TR><TD align='center' colspan='3'><B>Record Size:&nbsp;</B>");
		sbf.append("<input type='text' name='rsz' value='1' style='font-size: 8pt'>");
		sbf.append("</TD></TR>");

		sbf.append("<TR><TD align='center' colspan='3'>");
		sbf.append("<input type='submit' name='B' value='Select' style='font-size: 8pt'>");
		sbf.append("</TD></TR>");
		sbf.append("</TABLE>");
		sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
		sbf.append("<input type='hidden' name='aid' value='"+select_call_back+"'>");
		sbf.append("</FORM>");

		return sbf;
	    }
	}
	
	if(in == null || error != null) {
	    sbf = new StringBuffer("<CENTER>");
	    sbf.append("<BR><H3>Please cut and paste your HTML file into text area</H3>");
	    if(error != null) {
		sbf.append("<img src='/images/star.gif' border='0'>");
		sbf.append("<I>"+error+"</I><BR>");
	    }
	    sbf.append("<BR>");
	    sbf.append("<TABLE border='0'>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<FORM method='post' action='"+call_path+"'>");
	    sbf.append("<TEXTAREA name='html_text' rows='20' cols='60'>");
	    sbf.append("</TEXTAREA>");
	    sbf.append("</TD></TR>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<input type='submit' name='B' value='Preview' style='font-size: 8pt'>");
	    sbf.append("<input type='reset' name='R' value='Reset' style='font-size: 8pt'>");
	    sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
	    sbf.append("<input type='hidden' name='aid' value='"+get_data_call_back+"'>");
	    sbf.append("</FORM>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	    sbf.append("</CENTER>");
	}
	return sbf;
    }

    public StringBuffer getSelectedData (HttpServletRequest request, String mid, String save_call_back) {
	String call_path   = request.getServletPath();
	StringBuffer error   = null;
	StringBuffer sbf   = null;
	
	String aid   = request.getParameter("aid");
	try {
	    Vector vrs = null;
	    Vector vr  = null;

	    String action = request.getParameter("B");
	    if(action == null) {
		return null;
	    }

	    String rsz   = null;
	    int rz       = 1;

	    //=======================================================================
	    // save record into database
	    //=======================================================================
	    if(action.equals("Save")) {
		sbf = new StringBuffer();
		sbf.append("<BR>query="+request.getParameter("query"));
		sbf.append("<BR>rows="+request.getParameter("t_rows"));
		sbf.append("<BR>columns="+request.getParameter("t_columns"));
		return sbf;
	    }

	    //=======================================================================
	    // update records vector
	    //=======================================================================

	    if(action.equals("Update") || action.equals("Unique")) {
		Vector drv = getSelectedValueV(request, "rows", 0);
		Vector dcv = getSelectedValueV(request, "columns", 0);
		String total_rows = request.getParameter("t_rows");
		String total_cols = request.getParameter("t_columns");
		rz = Integer.parseInt(total_cols)-dcv.size();

		vrs = new Vector();		
		for(int m=0; m< Integer.parseInt(total_rows); m++) {
		    if(!drv.contains(""+m)) {
			vr = new Vector();
			for(int n=0; n< Integer.parseInt(total_cols); n++) {
			    if(!dcv.contains(""+n)) {
				vr.add(request.getParameter("record"+m+":"+n));
			    }
			}
			if(action.equals("Unique")) {
			    if(!vrs.contains(vr)) {
				vrs.add(vr);
			    }
			}
			else {
			    vrs.add(vr);
			}
		    }
		}
	    }

	    //=======================================================================
	    // generate records vector from file
	    //=======================================================================
	    String start = null;
	    String end   = null;

	    if(action.equals("Select")) {
		start = request.getParameter("start");
		end   = request.getParameter("end");
		rsz   = request.getParameter("rsz");

		if(start == null || end == null) {
		    return (new StringBuffer("<BR><B>Please select your data range</B><BR>"));
		}

		int t1 = Integer.parseInt(end);
		int t2 = Integer.parseInt(start);
		rz = Integer.parseInt(rsz);

		if((t1-t2+1)%rz != 0) {
		    error = new StringBuffer();
		    error.append("<I>Total ["+(t1-t2+1)+"] lines selected.</I><BR>");
		    error.append("<I>System can't generate record at size ["+rsz+"]</I>");
		}

		vrs = new Vector();
		vr  = new Vector();
		int m = t2;
		int j = 0;

		for(; m<=t1; m++) {
		    vr.add(request.getParameter("text"+m));
		    j++;
		    if(j == rz) {
			vrs.add(vr);
			j = 0;
			vr = new Vector();
		    }
		}
	    }

	    //=======================================================================
	    // display selected records
	    //=======================================================================
	    sbf = new StringBuffer();
	    sbf.append("<BR><h3>Total "+vrs.size()+" records have been generated</h3>");

	    if(error != null) {
		sbf.append("<TABLE border='0'><TR>");
		sbf.append("<TD><img src='/images/star.gif'></TD><TD>"+error+"</TD>");
		sbf.append("</TR></TABLE>");
	    }
		
	    sbf.append("<FORM method='post' action='"+call_path+"'>");
	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<input type='submit' name='B' value='Update' style='font-size: 8pt'>");
	    if(rz==1) {
		sbf.append("<input type='submit' name='B' value='Unique' style='font-size: 8pt'>");
	    }
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	    sbf.append("<TABLE border='1'>");
		
	    sbf.append("<tr><td>Delete</td>");

	    for(int k=0; k<rz; k++) {
		sbf.append("<td><input type='checkbox' name='columns"+k+"' value='"+k+"'></td>");
	    }
	    sbf.append("</tr>");

	    int row = 0;
	    int col = 0;
	    Enumeration enums = vrs.elements();
	    Enumeration enum  = null;
	    while (enums.hasMoreElements()) {
		enum = ((Vector)enums.nextElement()).elements();
		sbf.append("<tr><td><input type='checkbox' name='rows"+row+"' value='"+row+"'></td>");
		col = 0;
		while (enum.hasMoreElements()) {
		    sbf.append("<td>");
		    sbf.append("<input type='text' size='"+100/rz+"' name='record"+row+":"+col+"' ");
		    sbf.append(" value=\""+enum.nextElement()+"\"  style='font-size: 8pt'></td>");
		    col++;
		}
		sbf.append("</tr>");
		row++;
	    }

	 
	    sbf.append("</TABLE>");
	    sbf.append("<input type='hidden' name='t_rows' value='"+row+"'>");
	    sbf.append("<input type='hidden' name='t_columns' value='"+rz+"'>");

	    //==========================================================
	    // database selection
	    //==========================================================
	    Locale locale = request.getLocale();
	    ResourceBundle SystemInfo = ResourceBundle.getBundle("SystemInfo", locale); 
	    String databases   = SystemInfo.getString("3wcenter.databases");
	    sbf.append("<BR>");
	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<B>Database:</B>");
	    sbf.append("</TD>");
	    sbf.append("<TD align='center'>");

	    String database = request.getParameter("database");
	    sbf.append(MyHtml.getOptions("database", databases, ",", false, database, "style='font-size: 8pt'"));
	    sbf.append("</TD>");

	    //==========================================================
	    // table selection
	    //==========================================================
	    if(database != null && !database.startsWith("----")) {
		try {
		    Database db = DatabaseAdapter.getDatabase(database, SystemInfo);
		    Vector tnv = new Vector();
		    tnv = db.getTableNameV(database);
		    //System.out.println(tnv);
		    sbf.append("<TD align='center'>");
		    sbf.append("<B>Table:</B>");
		    sbf.append("</TD>");
		    sbf.append("<TD align='center'>");
		    String table_name = request.getParameter("table_name");
		    sbf.append(MyHtml.getOptions("table_name", tnv, false, table_name));
		    sbf.append("</TD>");
		    
		    sbf.append("<TD align='center'>");
		    sbf.append("<B>Table Info:</B>");
		    sbf.append("</TD>");
		    sbf.append("<TD align='center'>");
		    sbf.append("<input type='checkbox' name='show_table_info' value='1'>");
		    sbf.append("</TD>");
		}
		catch (Exception e) {
		    System.out.println("adminHtmlFileToTable:[getting database table names]:Error:"+e);
		}
	    }

	    sbf.append("</TR>");
	    sbf.append("</TABLE>");

	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<TEXTAREA name='query' rows='3' cols='60'>");
	    sbf.append("INSERT INTO TABLE_NAME (");
	    for(int nn=1; nn<=rz;nn++) {
		sbf.append("F"+nn);
		if(nn != rz) {
		    sbf.append(",");
		}
	    }
	    sbf.append(") VALUES (");
	    for(int nn=1; nn<=rz; nn++) {
		sbf.append("?");
		if(nn != rz) {
		    sbf.append(",");
		}
	    }
	    sbf.append("); </TEXTAREA>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");

	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<input type='submit' name='B' value='Update' style='font-size: 8pt'>");
	    if(rz==1) {
		sbf.append("<input type='submit' name='B' value='Unique' style='font-size: 8pt'>");
	    }
	    sbf.append("<input type='submit' name='B' value='Save' style='font-size: 8pt'>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	    sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
	    sbf.append("<input type='hidden' name='aid' value='"+aid+"'>");
	    sbf.append("</FORM>");

	    //=================================================================
	    // show table info
	    //================================================================
	    String show_table_info = request.getParameter("show_table_info");
	    String table_name = request.getParameter("table_name");

	    if(show_table_info != null && show_table_info.equals("1") && table_name != null && !table_name.startsWith("---")) {
		try {
		    Database db = DatabaseAdapter.getDatabase(database, SystemInfo);
		    adminDatabaseManagerBean abean = new adminDatabaseManagerBean();
		    sbf.append(abean.getTableInfo(db, table_name, false));
		}
		catch (Exception e) {
		    System.out.println("adminHtmlFileToTable:Error:getSelectedData:[show table info]"+e);
		}
	    }
	}
	catch (Exception e) {
	    System.out.println("adminHtmlFileToTable:Error:getSelectedData:"+e);
	    //System.out.println(DebugBean.getInputParameters(request));
	}
	return sbf;	
    }
    
    public Vector getSelectedRecordsV (HttpServletRequest request, String mid, String call_back) {
	String call_path   = request.getServletPath();
	HttpSession session  = request.getSession(true);
	Vector vrs = (Vector)session.getAttribute("RecordsVector");

	try {
	    Vector dvrs = new Vector();
	    Vector dvcs = new Vector();
	    String tempn = null;
	    String tempv = null;

	    Enumeration enum = request.getParameterNames();
	    while(enum.hasMoreElements()) {
		tempn  = (String)enum.nextElement();
		if(tempn.startsWith("row")) {
		    tempv = request.getParameter(tempn);
		    if(tempv != null && tempv.length()>0) {
			dvrs.add(tempv);
		    }
		}
		if(tempn.startsWith("column")) {
		    tempv = request.getParameter(tempn);
		    if(tempv != null && tempv.length()>0) {
			dvcs.add(tempv);
		    }
		}
	    }
	 
	    //========================================================
	    // delete rows
	    //========================================================
	    enum = dvrs.elements();
	    String dindex = null;
	    while (enum.hasMoreElements()) {
		dindex = (String)enum.nextElement();
		System.out.println("deleted="+dindex);
		vrs.removeElementAt(Integer.parseInt(dindex));
	    }
	    vrs.trimToSize();
	}
	catch (Exception e) {
	    System.out.println("adminHtmlFileToTable:Error:getSelectedRecordsV:"+e);
	    //System.out.println(DebugBean.getInputParameters(request));
	}
	return vrs;	
    }

    private Vector getSelectedValueV(HttpServletRequest request, String sname, int limit) {
	Vector v = new Vector();
	String tempn = null;
	String tempv = null;

	Enumeration enum = request.getParameterNames();
	while(enum.hasMoreElements()) {
	    tempn  = (String)enum.nextElement();
	    if(tempn.startsWith(sname)) {
		tempv = request.getParameter(tempn);
		if(tempv != null && tempv.length()>=limit) {
		    v.add(tempv);
		}
	    }
	}
	return v;
    }

    public StringBuffer displaySelectedRecors (HttpServletRequest request, String mid, String call_back) {
	String call_path   = request.getServletPath();
	HttpSession session  = request.getSession(true);
	Vector vrs = null;
	StringBuffer sbf = null;
	try {
	    vrs = (Vector)session.getAttribute("RecordsVector");
	    
	    sbf = new StringBuffer();
	    if(vrs == null) {
		return sbf.append("No record has been found.");
	    }

	    sbf.append("<BR><h3>Total "+vrs.size()+" records</h3>");
	    sbf.append("<FORM method='post' action='"+call_path+"'>");
	    sbf.append("<TABLE border='1'>");

	    Enumeration enums = vrs.elements();
	    Enumeration enum  = null;
	    while (enums.hasMoreElements()) {
		enum = ((Vector)enums.nextElement()).elements();
		while (enum.hasMoreElements()) {
		    sbf.append("<td>"+enum.nextElement()+"</td>");
		}
		sbf.append("</tr>");
	    }

	    sbf.append("</TABLE>");

	    sbf.append("<TABLE>");
	    sbf.append("<TR><TD align='center'>");
	    sbf.append("<input type='submit' name='B' value='Update' style='font-size: 8pt'>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	    sbf.append("<input type='hidden' name='mid' value='"+mid+"'>");
	    sbf.append("<input type='hidden' name='aid' value='"+call_back+"'>");
	    sbf.append("</FORM>");
	}
	catch (Exception e) {
	    System.out.println("adminHtmlFileToTable:Error:displaySelectedRecords:"+e);
	}
	return sbf;	
    }
    

    /*
      out.println("<FORM method=post action=adminWebTextServlet>");
	    out.println("<H2>Please Select Data Range</H2>");
	    out.println("<TABLE border=1  cellSpacing=0 cellPadding=0 style='font-size: 10pt' width=100%>");
	    out.println("<TR><TD><TEXTAREA name=url rows=20 cols=100>");
	    out.println(url);
	    out.println("</TEXTAREA></TD></TR>");
	    out.println("<TR><TD align=center hight=50>");
	    out.println("<input type=submit value='Load Data' style='font-size: 8pt'>");
	    out.println("<input type=hidden name=action value=load_data style='font-size: 8pt'>");
	    out.println("</TD></TR>");
	    out.println("</FORM>");
	    out.println("</TABLE>");
	    out.println("</BODY></HTML>");
	    response.flushBuffer();
	    return;
	}

	if(action.equals("load_data")) {
	    url = request.getParameter("url");
	    String start_str =  SystemInfo.getString("datek.url.string.start");
	    String end_str   =  SystemInfo.getString("datek.url.string.end");
	    String temp = null;

	    if(url.startsWith("https://")) {
		MyHttpsConnection cn = new MyHttpsConnection();
		cn.connectToUrl(url);
		out.println("<HTML><BODY><CENTER>");
		out.println("<FORM method=post action=adminWebTextServlet>");
		out.println("<TABLE border=1  cellSpacing=0 cellPadding=0 style='font-size: 10pt' width=100%>");
		out.println("<TR><TD><TEXTAREA name=input_str rows=20 cols=100>");
		
		Vector v = cn.getReturnLineVector();
		Enumeration enum = v.elements();
		int total = 0;
		while (enum.hasMoreElements()) {
		    temp = (String)enum.nextElement();
		    if(temp != null && temp.startsWith(start_str) && temp.endsWith(end_str)) {
			temp = temp.substring(temp.indexOf("symb="));
			temp = temp.replaceAll(end_str, "");
			if(!temp.startsWith("symb=1") && !temp.startsWith("symb=6") && 
			   !temp.startsWith("symb=2") && !temp.startsWith("symb=7") && 
			   !temp.startsWith("symb=3") && !temp.startsWith("symb=8") && 
			   !temp.startsWith("symb=4") && !temp.startsWith("symb=9") && 
			   !temp.startsWith("symb=5") && !temp.startsWith("symb=0")) {
			    out.println(temp+";");
			    total++;
			}
		    }
		}
		
		out.println("</TEXTAREA></TD></TR>");
		out.println("<TR><TD align=centee>Total Record:"+total+"</TD></TR>");
	    }
	  
	    out.println("<TR><TD align=center>");
	    StringTokenizer tokens = new StringTokenizer(databases, ",");

	    while (tokens.hasMoreTokens()) {
		temp = tokens.nextToken();
		out.println("<input type=checkbox name="+temp+" value="+temp+">"+temp+" &nbsp;");
	    }

	    out.println("</TD></TR>");

	    out.println("<TR><TD align=center hight=50>");
	    out.println("<input type=submit value='Update Database' style='font-size: 8pt'>");
	    out.println("<input type=hidden name=action value='update_sid' style='font-size: 8pt'>");
	    out.println("</TD></TR>");
	    out.println("</FORM>");
	    out.println("</TABLE>");
	    out.println("</BODY></HTML>");
	    response.flushBuffer();
	    return;
	}

	if(action.equals("update_sid")) {
	    String input_str = request.getParameter("input_str");
	    String temp  = null;
	    String sdb   = null;

	    //out.println("<BR>input string length="+input_str.length());
	    out.println("<HTML><HEAD><TITLE></TITLE></HEAD><BODY><CENTER>");
	    out.println("<H1>Excution Result</H1>");
	    
	    out.println("<TABLE border=1 style='font-size: 10pt' width=90%>");
	    
	    StringTokenizer tokens_db = new StringTokenizer(databases, ","); 	
	  
	    while (tokens_db.hasMoreTokens()) {
		int total =0;
		long stime = System.currentTimeMillis();
		temp = tokens_db.nextToken();
		sdb  = request.getParameter(temp);
		if(sdb != null && sdb.equals(temp)) {
		    Database db = DatabaseAdapter.getDatabase(sdb, SystemInfo);
		    String query = null;
		    String osid  = null;
		    StringTokenizer tokens_query = new StringTokenizer(input_str, ";");
		    String tick = null;
		    String sid  = null;
		    while (tokens_query.hasMoreTokens()) {
			temp = tokens_query.nextToken();
			if(temp != null && (temp.trim()).startsWith("symb=")) {
			    tick  = temp.substring(   temp.indexOf("symb=")+5,   temp.indexOf("&sid") );
			    sid   = temp.substring(temp.indexOf("&sid=")+5);
			    query = "SELECT * FROM STOCK_SID WHERE TICK='"+tick+"' AND URL='datek';";
			    osid  = db.getSingleFieldValue(query,"SID");
			    if(osid != null && osid.length()>1) {
				if(!osid.equals(sid)) {
				    total++;
				    query = "UPDATE STOCK_SID SET SID='"+sid+"' WHERE TICK='"+tick+"' AND URL='datek';";
				    out.println("<TR><TD>Database</TD><TD>"+sdb+"</TD><TD>Update</TD>");
				    out.println("<TD>Result</TD><TD>"+db.update(query)+"</TD></TR>");
				    out.println("<TR><TD>Query</TD><TD colspan=4>"+query+"</TD></TR>");
				}
			    }
			    else {
				total++;
				query = "INSERT INTO STOCK_SID (TICK, SID, URL) VALUES('"+tick+"','"+sid+"', 'datek');";
				out.println("<TR><TD>Database</TD><TD>"+sdb+"</TD><TD>Insert</TD>");
				out.println("<TD>Result</TD><TD>"+db.insert(query)+"</TD></TR>");
				out.println("<TR><TD>Query</TD><TD colspan=4>"+query+"</TD></TR>");
			    }
			}
			else {
			    if(temp != null && temp.length()>1) {
				out.println("<BR>Junk Found="+temp);
			    }
			}		
		    }
		}
		out.println("<BR>Database["+sdb+"]");
		out.println("<BR>Total Record["+total+"]");
		out.println("<BR>Total Time["+(System.currentTimeMillis()-stime)+"]");
	    }
	  
	    out.println("</TABLE>");
	    out.println("</BODY></HTML>");
	    return;
	}

	if(action.equals("Other")) {
	    out.println("<HTML><BODY><CENTER>");
	    out.println("<H1>Please Enter The URL</H1>");
	    out.println("<BR><BR>");
	    out.println("<TABLE border=1  cellSpacing=0 cellPadding=0 style='font-size: 10pt'>");
	    out.println("<FORM action=adminWebTextServlet>");
	    out.println("<TR><TD align=left><input type=text name=url value=http:// size=100></TD></TR>");
	    out.println("<TR><TD colspan=2 align=center height=50>");
	    out.println("<input type=submit name=action value='Original Page' style='font-size: 8pt'>");
	    out.println("<input type=submit name=action value='Line By Line' style='font-size: 8pt'>");
	    out.println("<input type=submit name=action value='Set Range' style='font-size: 8pt'>");
	    out.println("</TD></TR>");
	    out.println("</FORM>");
	    out.println("</TABLE>");
	    out.println("</BODY></HTML>");
	    return;
	}

	if(action.equals("Original Page") || action.equals("Line By Line")) {
	    if(url.startsWith("https://")) {
		MyHttpsConnection cn = new MyHttpsConnection();
		cn.connectToUrl(url);
		out.println("<HTML><BODY><CENTER>");
		out.println("<TABLE border=1  cellSpacing=0 cellPadding=0 style='font-size: 10pt' width=100%>");
		if(action.equals("Original Page")) {
		    String temp = (cn.getFullReturnStringBuffer()).toString();
		    if(temp != null && temp.indexOf("<") != -1) {
			temp = temp.replaceAll("<", "&lt");
		    }
		    if(temp != null && temp.indexOf(">") != -1) {
			temp = temp.replaceAll(">", "&gt");
		    }
		    out.println("<TR><TD>");
		    out.println(temp);
		    out.println("</TD></TR>");
		}
		if(action.equals("Line By Line")) {
		    String temp = null;
		    out.println("<TR><TD>");
		    Vector v = cn.getReturnLineVector();
		    Enumeration enum = v.elements();
		    while (enum.hasMoreElements()) {
			temp = (String)enum.nextElement();
			if(temp != null && temp.indexOf("<") != -1) {
			    temp = temp.replaceAll("<", "&lt");
			}
			if(temp != null && temp.indexOf(">") != -1) {
			    temp = temp.replaceAll(">", "&gt");
			}
			out.println("<BR>"+temp);
		    }
		    out.println("</TD></TR>");
		}

		out.println("</TABLE>");
		out.println("</BODY></HTML>");
	    }

	    if(url.startsWith("http://")) {
		MyHttpConnection cn = new MyHttpConnection();
		out.println("<HTML><BODY><CENTER>");
		out.println("<TABLE border=1  cellSpacing=0 cellPadding=0 style='font-size: 10pt' width=100%>");
		
		if(cn.connectToUrl(url)) {
		    if(action.equals("Original Page")) {
			String temp = (cn.getFullReturnStringBuffer()).toString();
			out.println("<TR><TD>");
			out.println("<TR><TD><TEXTAREA name=query rows=30 cols=74>"+temp+"</TEXTAREA></TD></TR>");
			out.println("</TD></TR>");
		    }

		    if(action.equals("Line By Line")) {
			String temp = null;
			out.println("<TR><TD>");
			Vector v = cn.getReturnLineVector();
			Enumeration enum = v.elements();
			while (enum.hasMoreElements()) {
			    temp = (String)enum.nextElement();
			    if(temp != null && temp.indexOf("<") != -1) {
				temp = temp.replaceAll("<", "&lt");
			    }
			    if(temp != null && temp.indexOf(">") != -1) {
				temp = temp.replaceAll(">", "&gt");
			    }
			    out.println("<BR>"+temp);
			}
			out.println("</TD></TR>");
		    }
		}
		else {
		    out.println(cn.getMessage());
		}
		out.println("</TABLE>");
		out.println("</BODY></HTML>");
	    }
	    return;
	}
    */
}








